/****************************************************************************************/
/*                                                                     					*/
/*  M16C/62P Group Program Collection                                  					*/
/*                                                                     					*/
/*  FILE NAME : serial.h                               		        					*/
/*  CPU       : This program is the Serial flash boot loader by Xmodem data transfer	*/
/*  HISTORY   : 2006.12.08 Ver 0.01                                    					*/
/*                                                                    	 				*/
/*  Copyright (C) 2006. Renesas Technology Corp.                       					*/
/*  Copyright (C) 2006. Renesas Solutions Corp.                        					*/
/*  All right reserved.                                                					*/
/*                                                                     					*/
/*****************************************************************************************/

#ifndef _SERIAL_H
#define _SERIAL_H

#define CLOCK			28000000L

#define XMODEM_SERIAL_CH	0

// serial port access
#define NO_OF_SCI_CHANNELS	5

// prescaler n = 0
#define	BAUD(B)				( ( CLOCK / 1 / 16 / B ) - 1 )

#define LINEFEED			10
#define CARRIAGE_RETURN		13
#define ESCAPE				27
#define BACKSPACE			8

// status info
#define OK					0
#define ERROR				1
#define TIMEOUT				2

#define TX_IN_PROGRESS		1
#define TX_NOT_IN_PROGRESS	0

// function prototypes
void InitSci ( void );
void SendByte ( unsigned char b );
void SendString ( char far *str );
void PurgeComms (unsigned long timeout );
static void ClearSCITxFlag( void );
static unsigned char RxByteWaiting ( void );
static unsigned char TxByteEmpty ( void );
static void TxByteLoad( unsigned char b );
unsigned short GetByte ( unsigned long timeout );

// structure definitions
union union_c2s {
		unsigned char uc[2];		//	m16c
									//	uc[0] -> lsb (b7--b0)
									//	uc[1] -> msb (b15--b8)
		unsigned short us;
};

#pragma INTERRUPT u0rec_handler(vect=18);
void  CommInit (void);

#endif
